(function() {
    angular.module('app').factory('attrBroadComponentService', attrBroadComponentService);

    attrBroadComponentService.$inject = ['util', '$q'];

    function attrBroadComponentService(util, $q) {
        return {
            get: _get
        }


        function _get(json) {

            var defer = $q.defer();

        
            util.$get({
                url: '/marketconditions/property/getCategoryPropertyStatisticTop.htm',
                data: json

            }).then(function(resp) {

                if (resp.value.length == 0) {

                    defer.reject([]);
                    return;
                }

                var arry = [];

                var data = resp.value[0].topCombProp; //string

                if (data.length == 0) {
                    //arry = []
                } else {

                    angular.forEach(data.split(',,'), function(item) {
                        arry.push({
                            title: item.split('::')[0],
                            sellMoney: Number(item.split('::')[1])
                        });
                    });
                    arry.sort(function(n, m) {
                        return m.sellMoney - n.sellMoney;
                    });


                }

                defer.resolve(arry);

            }, function(err) {

                defer.reject(err);
            });


            return defer.promise;
        }
    }
})();
